package idv.cjcat.pyronova.nodes {
	import flash.filters.ColorMatrixFilter;
	import flash.geom.Point;
	import idv.cjcat.pyronova.render.Graphics;
	import idv.cjcat.pyronova.render.RenderVisitor;
	import idv.cjcat.pyronova.utils.ColorMatrix;
	
	public class Tint extends Node {
		
		private var _red:int;
		public function get red():int { return _red; }
		public function set red(value:int):void {
			_red = value;
			_filter.matrix = ColorMatrix.tint(_red, _green, _blue);
		}
		
		private var _green:int;
		public function get green():int { return _green; }
		public function set green(value:int):void {
			_green = value;
			_filter.matrix = ColorMatrix.tint(_red, _green, _blue);
		}
		
		private var _blue:int;
		public function get blue():int { return _blue; }
		public function set blue(value:int):void {
			_blue = value;
			_filter.matrix = ColorMatrix.tint(_red, _green, _blue);
		}
		
		private var _filter:ColorMatrixFilter;
		
		public function Tint(red:int = 0, green:int = 0, blue:int = 0) {
			_filter = new ColorMatrixFilter();
			_red = red;
			_green = green;
			_blue = blue;
			_filter.matrix = ColorMatrix.tint(_red, _green, _blue);
		}
		
		private var g:Graphics;
		private var point:Point = new Point();
		override public function render(visitor:RenderVisitor):void {
			g = visitor.graphics();
			g.topBuffer().applyFilter(g.topBuffer(), g.rect(), point, _filter);
		}
	}
}